package com.example.aiodemo.test;

import java.util.*;

public class Main1 {
    public static void main(String[] args) {
        String[] inputStrings = inputStrings();
        System.out.println(Arrays.toString(inputStrings));
        for (int i = 0; i < inputStrings.length; i++) {
            String inputString = inputStrings[i];//每次输入的字符串
            int inputStringLength = inputString.length();//每次输入字符串的长度
            if (!(inputStringLength > 8)) {
                String s = addZero(inputString);
                System.out.println(s);
                if (inputStringLength == 8) {
                    System.out.println("00000000");
                }
            } else {
                String[] subStrings;//长度为8的字符串组成的数组
                if (inputStringLength % 8 == 0) {
                    subStrings = new String[inputStringLength / 8];
                    for (int j = 0; j < inputStringLength / 8; j++) {
                        subStrings[j] = inputString.substring(j * 8, j * 8 + 8);
                    }
                    for (int j = 0; j < subStrings.length; j++) {
                        System.out.println(subStrings[j]);
                    }
                    System.out.println("00000000");
                } else {
                    subStrings = new String[inputStringLength / 8 + 1];
                    for (int j = 0; j < subStrings.length - 1; j++) {
                        subStrings[j] = inputString.substring(j * 8, j * 8 + 8);
                    }
                    String lastString = inputString.substring(inputStringLength - inputStringLength % 8, inputStringLength);
                    subStrings[subStrings.length - 1] = addZero(lastString);
                    for (int j = 0; j < subStrings.length; j++) {
                        System.out.println(subStrings[j]);
                    }
                }

            }
        }
    }

    public static String addZero(String s) {
        StringBuilder sBuilder = new StringBuilder(s);
        int length = sBuilder.length();
        if (length > 0) {
            for (int i = 0; i < 8 - length; i++) {//length在变化,不能用length()函数
                sBuilder.append("0");
            }
        }
        return s = sBuilder.toString();
    }

    public static String[] inputStrings() {
        Scanner input = new Scanner(System.in);
        int times = input.nextInt();
        String[] inputStrings = new String[times];
        input.nextLine();
        for (int i = 0; i < times; i++) {
            ArrayList<String> strings = new ArrayList<>();
            inputStrings[i] = input.nextLine();
//            System.out.println("inputStrings[i]"+inputStrings[i]);
            String inputString = inputStrings[i];
            char[] chars = inputString.toCharArray();

            for (char aChar : chars) {
                if (aChar != ' ') {
                    strings.add(aChar + "");
                }
            }
            String s = "";
            for (String string : strings) {
                s += string;
            }
            inputStrings[i] = s;
        }
        return inputStrings;
    }
}
